package com.example.aliyunsms;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class AliyunSmsApplication {

    public static void main0(String[] args) {
        SpringApplication.run(AliyunSmsApplication.class, args);
        /**
         * 说明：简单测试给手机发短信
         * regionId 区域
         * accessKeyId 阿里云的秘钥id
         * secret 阿里云的秘钥
         */
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                "LTAI5tKtLah8rRUThCBSV6a8",
                "3p8RiMlawXB34wRxJ8SHXK1oPGSVWX");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        // 请求方式
        request.setSysMethod(MethodType.POST);
        // 短信API产品名称（短信产品名固定，无需修改）
        request.setProduct("Dysmsapi");
        // 短信API产品域名（接口地址固定，无需修改）
        request.setSysDomain("dysmsapi.aliyuncs.com");
        // 模板信息，不可随意写
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("PhoneNumbers", "17551836244");
        request.putQueryParameter("SignName", "滕华伟的博客");
        request.putQueryParameter("TemplateCode", "SMS_275275600");
        request.putQueryParameter("TemplateParam", "{\"code\":\"666225\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(AliyunSmsApplication.class, args);

    }

}
